#include "global.h"

char                          g_szZookeeper[MY_MAX_NAME_LEN];
char             			  g_szInstPath[MY_MAX_PATH_LEN];
char             			  g_szConfPath[MY_MAX_PATH_LEN];
char              			  g_szExecName[MY_MAX_NAME_LEN];
unordered_map<string,string>* p_rdisMap;
struct event_base *           s_eventBase;

HtProfile  g_htProfile =
{
    -1,      /* m_nPort       */
    "",      /* m_szRedisIp   */
    "",      /* m_szRedisAuth */
    "",      /* m_szRedisChannel */
};

int GetExeAbsPath(char* pExeAbsPath, size_t zLen)
{
	char  szProcPidExe[300] = { 0 };
	char  szExeAbsPath[300] = { 0 };

	ssize_t z = 0;
	char*   p = NULL;

	sprintf(szProcPidExe, "/proc/%d/exe", getpid());
	z = readlink(szProcPidExe, szExeAbsPath, sizeof(szExeAbsPath));
	if(z > 0)
	{
		p = strrchr(szExeAbsPath, '/');
		if(!p)
			return -1;

		z = p - szExeAbsPath;
		if(z > zLen - 1)
			return -2;

		strncpy(pExeAbsPath, szExeAbsPath, z); 
		*(pExeAbsPath + z) = '\0';
		return 0;
	}

	return -3;
}

